<?php

/*
 * 数据层类,数据库连接
 * 说明:model都必须继承此类
 * @author  kane.xie  mr.ziyong@qq.com
 * @time 2010.5.10
 */

class Model {
    /*
     * 构造函数
     */

    var $db; //连接对象

//    public function __construct() {
//        try {
//            $this->db = new PDO(KC('db_type') . ':host=' . KC('db_host') . ';dbname=' . KC('db_name'), KC('db_user'), KC('db_password'));
//            $this->db->exec("set names utf8");
//        } catch (PDOException $e) {
//            print "Error: " . $e->getMessage() . "<br/>";
//            die();
//        }
//    }

    public function pdoConnect($persistent = false) {
        try {
            if ($persistent) {
                $dbh = new PDO(KC('db_type') . ':host=' . KC('db_host') . ';dbname=' . KC('db_name'), KC('db_user'), KC('db_password'), array(PDO::ATTR_PERSISTENT => true));
                $dbh->exec("set names utf8");
                return $dbh;
            } else {
                $dbh = new PDO(KC('db_type') . ':host=' . KC('db_host') . ';dbname=' . KC('db_name'), KC('db_user'), KC('db_password'));
                $dbh->exec("set names utf8");
                return $dbh;
            }
        } catch (PDOException$e) {
            return false;
        }
    }

}

?>